//
//  BaseTableViewController.swift
//  MQWeibo
//
//  Created by SYN on 15/11/12.
//  Copyright © 2015年 SYN. All rights reserved.
//

import UIKit

/**
    1.需要判断用户是否登陆
    2.如果登陆,执行正常功能
    3.如果没有登陆,需要"替换视图" -> loadView
*/

class BaseTableViewController: UITableViewController , visitorLoginViewDelegate{
    /**
    *  用户登陆标记
    */
    var userLogin = false
//    var userLogin = shareUserAccount != nil
    /**
    访客登陆视图
    */
    var visitor: VisitorLoginView?
    
    override func loadView() {
        //如果用户已登陆,直接返回
        if userLogin {
            //调用 loadView 的父类方法,执行原有代码
            super.loadView()
            
            return
        }
        //替换视图
        visitor = NSBundle.mainBundle().loadNibNamed("VisitorLoginView", owner: nil, options: nil).last as? VisitorLoginView
        
        visitor?.delegate = self
        
        view = visitor
        
        //设置导航栏按钮
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorRegisterDidSelected")
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginDidSelected")
        
    }
    /**
    *  未登录视图协议方法
    */
    
    func visitorLoginDidSelected() {
//        print("\(__FUNCTION__)")
        
        let sb = UIStoryboard(name: "OAuth", bundle: nil)
        
        presentViewController(sb.instantiateInitialViewController()!, animated: true, completion: nil)
        
    }
    
    func visitorRegisterDidSelected() {
//        print("\(__FUNCTION__)")
    }
    

}
